package com.auxgroup.hr.front.service.process.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import com.auxgroup.hr.front.dao.domain.PsCWfPayComp;
import com.auxgroup.hr.front.dao.domain.PsCWfPayHdr;
import com.auxgroup.hr.front.dao.repository.PsCWfPayCompRepository;
import com.auxgroup.hr.front.dao.repository.PsCWfPayHdrRepository;
import com.auxgroup.hr.front.service.process.WfPayHdrService;

/** 
 * @author lvliuhao 
 * @version 创建时间：2018年7月17日 下午9:42:00 
 * 类说明 
 */
@Service("wfPayHdrService")
public class WfPayHdrServiceImpl implements WfPayHdrService {
	
	@Autowired
	private PsCWfPayHdrRepository psCWfPayHdrRepository;
	
	@Autowired
	private PsCWfPayCompRepository psCWfPayCompRepository;

	@Override
	public PsCWfPayHdr getWfPayHdr(String transNum) {
		return psCWfPayHdrRepository.getOne(transNum);
	}

	@Override
	public List<PsCWfPayComp> getPayComps(String transNum, String calRunId) {
		PsCWfPayComp queryComp = new PsCWfPayComp();
		queryComp.setCalRunId(calRunId);
		queryComp.setcTransactionNbr(transNum);
		return psCWfPayCompRepository.findAll(Example.of(queryComp));
	}

	/* (non-Javadoc)
	 * @see WfPayHdrService#compAllToList(PsCWfPayComp)
	 */
	@Override
	public List<Map<String, Object>> compAllToList(PsCWfPayComp comp) {
		List<Map<String, Object>> dataList = new ArrayList<>();
		Map<String, Object> nowMonth = new HashMap<String, Object>();
		Map<String, Object> lastMonth = new HashMap<String, Object>();
		Map<String, Object> balance = new HashMap<String, Object>();
		if(comp!=null){
			//上月
			lastMonth.put("title", "上月");
			lastMonth.put("peopleNum", comp.getCount1());
			lastMonth.put("totalMoney", comp.getcAmt001());
			lastMonth.put("finalMoney", comp.getcAmt004());
			dataList.add(lastMonth);
			//本月
			nowMonth.put("title", "本月");
			nowMonth.put("peopleNum", comp.getCount2());
			nowMonth.put("totalMoney", comp.getcAmt002());
			nowMonth.put("finalMoney", comp.getcAmt005());
			dataList.add(nowMonth);
			//差额
			balance.put("title", "差额");
			balance.put("peopleNum", comp.getCount3());
			balance.put("totalMoney", comp.getcAmt003());
			balance.put("finalMoney", comp.getcAmt006());
			dataList.add(balance);
			return dataList;
		}
		return null;
	}

	@Override
	public List<Map<String, Object>> compToCompList(List<PsCWfPayComp> comps) {
		List<Map<String, Object>> data = new ArrayList<Map<String,Object>>();
		Map<String, Object> compMap;
		PsCWfPayComp allComp = null;
		if(comps!=null&&!comps.isEmpty()){
			for (PsCWfPayComp comp : comps) {
				if(!"ALL".equals(comp.getcPayCompany())){
					compMap = new HashMap<String, Object>();
					compMap.put("title", comp.getDescr());
					compMap.put("peopleNum", comp.getCount2());
					compMap.put("totalMoney", comp.getcAmt002());
					compMap.put("finalMoney", comp.getcAmt005());
					data.add(compMap);
				}else{
					allComp = comp;
				}
			}
		}
		if(allComp!=null){
			compMap = new HashMap<String, Object>();
			compMap.put("title", "合计");
			compMap.put("peopleNum", allComp.getCount2());
			compMap.put("totalMoney", allComp.getcAmt002());
			compMap.put("finalMoney", allComp.getcAmt005());
			data.add(compMap);
		}
		return data;
	}
}
 